getwd()
setwd("~/Dropbox/4-Baylor-Gorelick/Manuscripts/3-Pla2g12b/_Finalized_Pla2g12b_Folders/Panels/main-3c-co-IP-wt-v-KO")
getwd()
###https://bioconductor.org/packages/release/bioc/vignettes/EnhancedVolcano/inst/doc/EnhancedVolcano.html

if (!requireNamespace('BiocManager', quietly = TRUE))
  install.packages('BiocManager')
BiocManager::install('EnhancedVolcano')
devtools::install_github('kevinblighe/EnhancedVolcano')
library(EnhancedVolcano)
a
YES

classes <- c(names="character", log2FC="numeric", padj="numeric")
WTCOIP <- read.csv("WTCOIPV3.csv", colClasses=classes, stringsAsFactors=FALSE)
head(WTCOIP)
sapply(WTCOIP, mode)

EnhancedVolcano(WTCOIP,
                lab = WTCOIP$names,
                x = 'log2FC',
                y = 'padj',
                pCutoff = .5,
                FCcutoff = .5,
                drawConnectors = F,
                boxedLabels=F,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 3.0,
                labSize = 5.0,
                xlim=c(-4,4),
                ylim=c(0,2)
)

EnhancedVolcano(WTCOIP,
                lab = NA,
                x = 'log2FC',
                y = 'padj',
                pCutoff = .15,
                FCcutoff = 1,
                drawConnectors = F,
                boxedLabels=F,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 5.0,
                labSize = 5.0,
                xlim=c(-30,30),
                ylim=c(0,7),
                gridlines.major = FALSE,
                gridlines.minor = FALSE
)


EnhancedVolcano(WTCOIP,
                lab = WTCOIP$names,
                x = 'log2FC',
                y = 'padj',
                pCutoff = .15,
                FCcutoff = 1,
                drawConnectors = F,
                boxedLabels=F,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 5.0,
                labSize = 5.0,
                xlim=c(-30,30),
                ylim=c(0,10),
                gridlines.major = FALSE,
                gridlines.minor = FALSE
)


classes <- c(names="character", log2FC="numeric", padj="numeric")
FUNCCOIP <- read.csv("FUNCCOIPV4.csv", colClasses=classes, stringsAsFactors=FALSE)
head(FUNCCOIP)
sapply(FUNCCOIP, mode)

EnhancedVolcano(FUNCCOIP,
                lab = FUNCCOIP$names,
                x = 'log2FC',
                y = 'padj',
                pCutoff = .05,
                FCcutoff = 2,
                drawConnectors = F,
                boxedLabels=F,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 5.0,
                labSize = 5.0,
                xlim=c(-30,30),
                ylim=c(0,5),
                gridlines.major = FALSE,
                gridlines.minor = FALSE
)


EnhancedVolcano(FUNCCOIP,
                lab = NA,
                x = 'log2FC',
                y = 'padj',
                pCutoff = .05,
                FCcutoff = 1,
                drawConnectors = F,
                boxedLabels=F,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 5.0,
                labSize = 5.0,
                xlim=c(-30,30),
                ylim=c(0,5),
                gridlines.major = FALSE,
                gridlines.minor = FALSE
)




















classes <- c(names="character", log2FC="numeric", padj="numeric")
res_4dpf <- read.csv("res_4d.csv", colClasses=classes, stringsAsFactors=FALSE)
head(res_4dpf)
sapply(res_4dpf, mode)

EnhancedVolcano(res_4dpf,
                lab = res_4dpf$names,
                x = 'log2FC',
                y = 'padj',
                pCutoff = 1e-3,
                FCcutoff = .5,
                drawConnectors = T,
                col=c('black', 'black', 'black', 'green'),
                pointSize = 3.0,
                labSize = 8.0,
                xlim=c(-4,4),
                ylim=c(0,30)
)

EnhancedVolcano(res_4dpf,
                lab = NA,
                x = 'log2FC',
                y = 'padj',
                pCutoff = 1e-5,
                FCcutoff = .5,
                drawConnectors = F,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 5.0,
                labSize = 8.0,
                xlim=c(-3,2),
                ylim=c(0,20),
                gridlines.major = FALSE,
                gridlines.minor = FALSE
)


res_2d <- read.table("res_2d.txt", header = TRUE)
head(res_2d)
res_4d <- read.table("res_4d.txt", header = TRUE)
head(res_4d)



DF2dpf<-as.data.frame(res_2d)
transform(DF2dpf, log2FC = as.numeric(log2FC))


class(res_2d$log2FC)
res_2d<-as.numeric(res_2d$log2FC)
class(res_2d$log2FC)

sapply(res_2d, mode)
transform(res_2d, log2FC = as.numeric(log2FC))
sapply(res_2d, mode)


res_2d_rev<-res_2d$names -  as.numeric(res_2d$log2FC)- as.numeric(res_2d$padj)
class(res_2d_rev$log2FC)

EnhancedVolcano(res_2d,
                lab = res_2d$names,
                x = 'log2FC',
                y = 'padj',
                pCutoff = 1e-4,
                FCcutoff = 0,
                drawConnectors = TRUE,
                col=c('black', 'black', 'black', 'green'),
                pointSize = 3.0,
                labSize = 8.0
                )


EnhancedVolcano(volc1,
                lab = NA,
                x = 'log2ibaq',
                y = 'pval',
                pCutoff = 1e-4,
                FCcutoff = 0,
                drawConnectors = TRUE,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 6.0,
                labSize = 8.0,
                ylim = 1e-7
)

EnhancedVolcano(volc2,
                lab = volc2$names,
                x = 'log2ibaq',
                y = 'pval',
                pCutoff = 5e-2,
                FCcutoff = 0,
                drawConnectors = TRUE,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 6.0,
                labSize = 8.0,
                ylim = 1e-7
)


EnhancedVolcano(volc2,
                lab = NA,
                x = 'log2ibaq',
                y = 'pval',
                pCutoff = 5e-2,
                FCcutoff = 0,
                drawConnectors = TRUE,
                col=c('black', 'black', 'black', 'red'),
                pointSize = 6.0,
                labSize = 8.0,
                ylim = 1e-7
)

EnhancedVolcano(volc2,
                lab = NA,
                x = 'log2ibaq',
                y = 'pval',
                pCutoff = 5e-2,
                FCcutoff = 0,
                drawConnectors = TRUE,
                col=c('black', 'black', 'black', 'black'),
                pointSize = 6.0,
                labSize = 8.0,
                ylim = 1e-7
)




install.packages('calibrate')
library(calibrate)

volc1 <- read.table("func-volcano.txt", header = TRUE)
head(volc1)

with(volc1, plot(ibaq, log10pval, pch=20, main="Volcano plot", xlim=c(-15,25)))

with(volc1, plot(log10pval, ibaq,  pch=20, main="Volcano plot", xlim=c(-6,6)))


#https://www.gettinggeneticsdone.com/2014/05/r-volcano-plots-to-visualize-rnaseq-microarray.html

with(subset(volc1, log10pval>5 & abs(FC)>3), points(FC, log10pval, pch=20, col="green"))

